package com.qf.iot.controller;

import com.qf.iot.core.vo.R;
import com.qf.iot.dto.PageDto;
import com.qf.iot.entity.QfDevice;
import com.qf.iot.service.Impl.QfDeviceServiceImpl;
import com.qf.iot.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：肖骏麟
 * 时间:2023/10/30 11:43
 * 描述：优化小子
 */
@RestController
@RequestMapping("/qfdevice")
@CrossOrigin
public class QfDeviceContrller {
    @Autowired
    private QfDeviceServiceImpl QfDeviceService;
    @PostMapping("page")
    public PageResult<QfDevice> page(@RequestBody PageDto<QfDevice> pageDto){

        return QfDeviceService.page(pageDto);
    }
    @PostMapping("save")
    public R save(@RequestBody QfDevice qfDevice){
        QfDeviceService.save(qfDevice);
        return R.ok(0,"success");
    }
    @GetMapping("all")
    public R all(@RequestParam String name){
        return R.ok(QfDeviceService.findDeviceList(name));
    }
    @PostMapping("delete/{id}")
    public R delete(@PathVariable String id){
        QfDeviceService.removeById(id);
        return R.ok(0,"success");
    }
    @GetMapping("/list")
    public R list(@RequestParam String name){
        List<QfDevice> deviceList = QfDeviceService.findListByDeviceName(name);
        return R.ok(deviceList);
    }
}
